﻿using org.xisoft.game.utils.game;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;

namespace ChessTest.Chess.Algorithms
{
    /// <summary>
    /// 算法的基类
    /// </summary>
    public abstract class AiAlgorithm : org.xisoft.game.utils.game.algorithms.AiAlgorithm<AiChessboard>
    {

        /// <summary>
        /// 当前棋盘是否存在历史里面（防止，走一样的）
        /// </summary>
        /// <returns></returns>
        protected bool ContainsHistory(AiChessboard aiChessboard)
        {
            //String keyword = aiChessboard.GetKeyword();
            /*foreach (String key in historyList)
            {
                if (key.Equals(keyword))
                    return true;
            }*/
            return false;
        }

        /// <summary>
        /// 所有走法
        /// </summary>
        /// <returns></returns>
        public override List<MoveAction> GetAllCanMoves(AiChessboard chessboard)
        {
            List<MoveAction> canMoveActions = new List<MoveAction>(32);

            AiChessboard aiChessboard = chessboard as AiChessboard;
            aiChessboard.ForeachMoviesChess(chessman =>
            {
                List<Point> points = chessman.GetCanMoveList(aiChessboard);
                foreach (Point point in points)
                {
                    MoveAction action = new MoveAction { CurrentChessman = chessman, OldChessman = aiChessboard.GetChessman(point.X, point.Y), ToX = point.X, ToY = point.Y };
                    if (action.OldChessman != null)
                        action.Score = action.OldChessman.Score;
                    canMoveActions.Add(action);

                }
            });

            return canMoveActions;
        }
    }
}
